package br.edu.utfpr.backuptools.BackupTools.view.action.configuracao;

import br.edu.utfpr.backuptools.BackupTools.app.Aplication;
import br.edu.utfpr.backuptools.BackupTools.controller.ControladorConfiguracaoImpl;
import br.edu.utfpr.backuptools.BackupTools.controller.interfaces.ControladorConfiguracao;
import br.edu.utfpr.backuptools.BackupTools.controller.validator.ConfiguracaoValidator;
import br.edu.utfpr.backuptools.BackupTools.controller.validator.RetornoValidacao;
import br.edu.utfpr.backuptools.BackupTools.model.dao.DaoConfiguracaoImpl;
import br.edu.utfpr.backuptools.BackupTools.model.dao.interfaces.DaoConfiguracao;
import br.edu.utfpr.backuptools.BackupTools.model.pojo.Configuracao;
import br.edu.utfpr.backuptools.BackupTools.view.action.AbstractAction;

public class SalvarConfiguracoesAction extends AbstractAction<Configuracao> {

	DaoConfiguracao dao = new DaoConfiguracaoImpl();
	ControladorConfiguracao controlador = new ControladorConfiguracaoImpl(dao,new ConfiguracaoValidator());

	@Override
	public RetornoValidacao execute(Configuracao bean) {
		try {
			RetornoValidacao rv = controlador.save(bean);
			if(rv.isOk())
			{
				Aplication.agendaBackups(bean);
			}
			return rv;
		} catch (Exception e) {
			e.printStackTrace();
			return new RetornoValidacao(false, "Desculpe, ocorreu um erro desconhecido ao salvar as configurações");
		}
	}

}
